package com.bluedot.www.core.common;


import java.lang.reflect.Method;
import java.util.Map;

/**
 * 管道，用于缓存service实例和映射关系
 *
 * @author He Peng
 * @version 1.0
 * @date 2021/8/13 15:03
 */
public class Pipe {

    /**
     * 存储Url和Service中方法的对应关系
     */
    private static Map<String, Method> handlerMapping;

    /**
     * 存储URL和Service实例的对应关系
     */
    private static Map<String, Object> serviceMapping;


    /**
     * 初始化管道
     *
     * @param handlerMapping: service方法和url的映射
     * @param serviceMapping: service实例和url的映射
     * @author He Peng
     * @date 2021/8/17 15:36
     */
    public Pipe(Map<String, Method> handlerMapping, Map<String, Object> serviceMapping) {
        Pipe.handlerMapping = handlerMapping;
        Pipe.serviceMapping = serviceMapping;
    }

    /**
     * 从管道中获取Service实例
     *
     * @param url: 请求链接
     * @return java.lang.Object
     * @author He Peng
     * @date 2021/8/17 15:37
     */
    public Object getServiceObject(String url) {
        return serviceMapping.get(url);
    }

    /**
     * 从管道中获取Service的Method方法
     *
     * @param url: 链接
     * @return java.lang.reflect.Method
     * @author He Peng
     * @date 2021/8/17 15:38
     */
    public Method getServiceMethod(String url) {
        return handlerMapping.get(url);
    }

}
